<template>
  <el-row :gutter="24" class="pl80">
    <el-col>
      <h2>家庭信息</h2>
    </el-col>
    <el-col>
      <e-table
        ref="eTable"
        @getList="handleGetList"
        :tableData="tableData"
        :columns="columns"
        :loading="loading"
        :pageObj="null"
      />
    </el-col>
  </el-row>
</template>

<script>
import { getUserFamily, deleteUserFamily } from '@/api/archives'
import { setSession, getSession } from '@/utils/util'

export default {
  data() {
    return {
      loading: false,
      tableData: [],
      columns: [
        {
          label: '称谓',
          prop: 'appellationName'
        },
        {
          label: '姓名',
          prop: 'name'
        },
        {
          label: '政治面貌',
          prop: 'politicalStatusName'
        },
        {
          label: '身份证号',
          prop: 'idCards'
        },
        {
          label: '工作单位',
          prop: 'workUnits'
        },
        {
          label: '手机号码',
          prop: 'phone'
        },
        { slot: 'action' }
      ],
      userRow: null
    }
  },
  methods: {
    handleShowHistory() {
      this.$emit('showHistory', 'family')
    },
    handleEdit(row) {
      this.$nextTick(() => {
        this.$refs.familyModal.edit(row)
      })
    },
    handleDelete(row) {
      const _this = this
      this.$confirm({
        title: '删除操作',
        content: `您确定删除[${row.name}]这条记录吗？`,
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        centered: true,
        async onOk() {
          // 调用删除接口，刷新表格数据
          const res = await deleteUserFamily(row.userFamilyId, {})
          openNotification('success', '删除成功')
          _this.handleGetList(_this.userRow.userId)
        }
      })
    },
    async handleGetList(id, param = {}) {
      this.loading = true
      const res = await getUserFamily(id, param)
      if (res && res.data.length > 0) {
        const { state, data } = res
        this.tableData = data
      } else {
        this.tableData = []
      }
      this.loading = false
    }
  },
  created() {
    if (this.$route.query.userRow) {
      this.userRow = JSON.parse(this.$route.query.userRow)
    } else {
      this.userRow = getSession('userRow')
    }
    // this.handleGetList(this.userRow.userId)
  }
}
</script>
